/**
  **************************************************************************
  * @file     at32f403a_407_board.h
  * @version  v2.1.0
  * @date     2022-06-09
  * @brief    header file for at-start board. set of firmware functions to
  *           manage leds and push-button. initialize delay function.
  **************************************************************************
  *                       Copyright notice & Disclaimer
  *
  * The software Board Support Package (BSP) that is made available to
  * download from Artery official website is the copyrighted work of Artery.
  * Artery authorizes customers to use, copy, and distribute the BSP
  * software and its related documentation for the purpose of design and
  * development in conjunction with Artery microcontrollers. Use of the
  * software is governed by this copyright notice and the following disclaimer.
  *
  * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
  * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
  * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
  * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
  * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
  * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
  *
  **************************************************************************
  */

#ifndef __HAL_GPIO_H
#define __HAL_GPIO_H

#ifdef __cplusplus
extern "C" {
#endif

#include "stdio.h"
#include "at32f403a_407.h"


#define ENCODER_PUSH_PORT        GPIOB
#define ENCODER_PUSH_PIN         GPIO_PINS_3
#define ENCODER_PUSH_CLK         CRM_GPIOB_PERIPH_CLOCK

#define ENCODER_A_PORT           GPIOB
#define ENCODER_A_PIN            GPIO_PINS_4
#define ENCODER_A_CLK            CRM_GPIOB_PERIPH_CLOCK

#define ENCODER_B_PORT           GPIOB
#define ENCODER_B_PIN            GPIO_PINS_5
#define ENCODER_B_CLK            CRM_GPIOB_PERIPH_CLOCK

/* External Interrupt  */
#define EXTI_PREEMPTIONPRIORITY_DEFAULT     2
#define EXTI_SUBPRIORITY_DEFAULT            1


typedef void(*EXTI_CallbackFunction_t)(void);


/******************** functions ********************/


/* button operation function */
void at32_button_init(void);
void exint_config(
		gpio_type *Port,
		uint8_t Pin,
    EXTI_CallbackFunction_t Function,
    exint_polarity_config_type Trigger_Mode,
    uint8_t PreemptionPriority,
    uint8_t SubPriority);
void attachInterrupt(gpio_type *Port, uint8_t Pin, EXTI_CallbackFunction_t Function, exint_polarity_config_type Trigger_Mode);


#ifdef __cplusplus
}
#endif

#endif

